package com.xinan.hygl;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.sql.Timestamp;
import java.util.List;
import java.sql.Date;

@TableBind(tableName = "hygl_zs")
public class HyglZs extends Model<HyglZs>{
    public static final HyglZs dao = new HyglZs();

    //columns START
    private String ID = "id";  //
    private String WPID = "wpid";  //物品id
    private String WPMC = "wpmc";  //物品名称
    private String FULXID = "fulxid";  //服务类型
    private String FULX = "fulx";  //服务类型名称
    private String CARD = "card";  //卡号
    private String DATE = "date";  //

    public void setId(int value) {
        set(ID, value);
    }

	public int getId() {
		return get(ID);
	}
    public void setWpid(String value) {
        set(WPID, value);
    }

	public String getWpid() {
		return get(WPID);
	}
    public void setWpmc(String value) {
        set(WPMC, value);
    }

	public String getWpmc() {
		return get(WPMC);
	}
    public void setFulxid(String value) {
        set(FULXID, value);
    }

	public String getFulxid() {
		return get(FULXID);
	}
    public void setFulx(String value) {
        set(FULX, value);
    }

	public String getFulx() {
		return get(FULX);
	}
    public void setCard(String value) {
        set(CARD, value);
    }

	public String getCard() {
		return get(CARD);
	}
    public void setDate(Timestamp value) {
        set(DATE, value);
    }

	public Timestamp getDate() {
		return get(DATE);
	}
	//columns END

    public List<HyglZs> findAll() {
        return find("select * from hygl_zs");
    }
    /**
     * @param   where
     * @return  Record
     */
    public List<Record> findAlls(String where) {
        String sqlExp = " from hygl_zs";
        if(StringKit.notBlank(where)){
                sqlExp += " where " + where;
        }
                return Db.find( "select * " +sqlExp );

    }

    public Page<HyglZs> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from hygl_zs";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select *", sqlExp);
    }
    
    public Page<HyglZs> pageAll(int pageNumber,int pageSize,String where){
    	if(StringKit.notBlank(where)){
    		where = " and zs.card='"+where+"'";
    	}
    	String sqlExp = "from hygl_zs zs,hygl h,cpgl_rk rk,hygl_fwgl fw where zs.card=h.card and (zs.wpid=rk.wpid or zs.fulxid=fw.id) "+where;
    	return paginate(pageNumber, pageSize, "select zs.*,fw.fwjg,h.yhm,h.dh,rk.jysj", sqlExp);
    }
}

